unit uSAF0000_03;

interface

uses
   Forms,
   SysUtils,
   Classes;

type
   TThreadCotacao = class(TThread)

   private

      { Private declarations }

   protected

      procedure fContacaoOnline;
      procedure Execute; override;

   public

   end;

implementation

{ Important: Methods and properties of objects in visual components can only be
  used in a method called using Synchronize, for example,

      Synchronize(UpdateCaption);

  and UpdateCaption could look like,

    procedure TTheadCotacao.UpdateCaption;
    begin
      Form1.Caption := 'Updated in a thread';
    end; }

{ TTheadCotacao }

uses
   uLibGlobal,

   uSAF0000_02;

procedure TThreadCotacao.Execute;
begin
   { Place thread code here }
   try
      with frmPrincipal do
      begin
         while not Terminated do
         begin
            Synchronize(fContacaoOnline);
            Application.ProcessMessages;
         end;
      end;
   finally
      Terminate;
   end;
end;

procedure TThreadCotacao.fContacaoOnline;
begin
   with frmPrincipal do
   begin
      Application.ProcessMessages;

      if fInternetConect then
      begin
         lblCotacaoDolarValor.Caption := fCotacaoMoeda('USD', 'BRL');
         lblCotacaoEuroValor.Caption := fCotacaoMoeda('EUR', 'BRL');
      end
      else
      begin
         lblCotacaoDolarValor.Caption := '0.0000';
         lblCotacaoEuroValor.Caption := '0.0000';
      end;

      lblCotacaoDolarValor.Update;
      lblCotacaoEuroValor.Update;
   end;
end;

end.

